{include file="public/header" /}
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <input name="id" value="{:isset($_info['id']) ? $_info.id: ''}" style="display: none">
        <label class="layui-form-label required">上级菜单</label>
        <div class="layui-input-block">
            <input placeholder="" readonly value="{:isset($parent['title']) ? $parent.title: '根目录'}" class="layui-input">
            <input name="pid" value="{:isset($parent['id']) ? $parent.id: 0}" style="display: none">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="菜单不能为空" placeholder="请输入菜单" value="{:isset($_info.title) ? $_info.title:''}" class="layui-input">
            <tip>填写菜单名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">URL地址</label>
        <div class="layui-input-block">
            <input type="text" name="name"  placeholder="请输入URL地址" value="{:isset($_info.name) ? $_info.name:''}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">启用状态:</label>
        <div class="layui-input-block">
            <select name="status" id="status" lay-verify="required">
                <option value="1" selected>启用</option>
                <option value="0">禁用</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">打开目标</label>
        <div class="layui-input-block">
            <input type="text" name="target"  value="{:isset($_info.target) ? $_info.target:'_self'}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">权限规则</label>
        <div class="layui-input-block">
            <input type="text" name="condition"  placeholder="请输入URL地址" value="{:isset($_info.condition) ? $_info.condition:''}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图标样式</label>
        <div class="layui-input-block">
            <input type="text" name="icon" placeholder="" value="{:isset($_info.icon) ? $_info.icon : ''}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="sort" placeholder="" value="{:isset($_info.sort) ? $_info.sort: 0}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="desc" class="layui-textarea" placeholder="请输入备注信息">{:isset($_info.desc) ? $_info.desc:''}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">显示:</label>
        <div class="layui-input-block">
            <select name="is_show" id="is_show" lay-verify="required" >
                <option value="1">是</option>
                <option value="0">否</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: "{:isset($_info['id']) ? url('edit'):url('add')}",
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                timeout: 2000,
                success: function (data1) {
                    if (data1.code == 0) {
                        layer.msg(data1.msg)
                        setTimeout(function () {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }, 1000);
                    } else {
                        layer.msg(data1.msg)
                    }
                },
                error: function () {
                    layer.msg("添加失败")
                }
            })
            /*var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
            });*/
            return false;
        });

        var status =  {:isset($_info.status) ? $_info.status : 1};
        var is_show =  {:isset($_info.is_show) ? $_info.is_show : 1};
        $('#is_show').find("option[value="+is_show+"]").attr("selected",true);
        $('#status').find("option[value="+status+"]").attr("selected",true);
        form.render('select')
    });
</script>
</body>
</html>